package com.cgah

import grails.test.*
import com.icegreen.greenmail.util.GreenMailUtil

class ExpiredListingDetectorJobTests extends GroovyTestCase {
    def greenMail

    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testExecute_putsMessageOnQueue() {
        // Prep
        ExpiredListingDetectorJob listingJob = new ExpiredListingDetectorJob()

        // It's not possible to save a Listing in the past, so we need to fake it.
        def listingServiceStub = new ListingServiceStub()
        listingJob.listingService = listingServiceStub

        // exec
        listingJob.execute()

        // This is where we would check the message queue.
        // assertTrue(queueContainsListing)
    }

        void testExecute_sendsMailMessage() {
        // Prep
        ExpiredListingDetectorJob listingJob = new ExpiredListingDetectorJob()

        // It's not possible to save a Listing in the past, so we need to fake it.
        def listingServiceStub = new ListingServiceStub()
        listingJob.listingService = listingServiceStub

        // exec
        listingJob.execute()

        // This is where we would check the message queue.
        assertNotNull(greenMail.getReceivedMessages());
    }
}

class ListingServiceStub implements com.cgah.api.ListingService
{
    def create(Object params) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def save(Object params, Object userName, Object password) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def save(Object params, Object seller) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def list(Object params, Object userName, Object password) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def list(Object params) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def listAllForUser(Object params, Object userName, Object password) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def listAllForUser(Object params, Object userId) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def getListingById(Object id, Object userName, Object password) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def getListingById(Object id) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def updateListing(Object params, Object userName, Object password) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def updateListing(Object params) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def lastBids(Object id, Object max, Object userName, Object password) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def lastBids(Object id, Object max) {
        return null  //To change body of implemented methods use File | Settings | File Templates.
    }

    def getExpiredListings()
    {
        Customer seller = new Customer(username: "blabababa", emailAddress: "asdf@asdf.com", createdDate: new Date(), password: "12312312", enabled: true);
        return new Listing(createdDateTime:new Date(),  description: "asdf", seller:seller, startingBidPrice: 11.0f, name: "test", endDateTime: (new Date())-1);
    }

}
